using System;
using System.Reflection;

namespace Needle.Utils {
    /// <summary>
    /// Helper class for Attribute usage.
    /// </summary>
    public static class Attributes {
        /// <summary>
        /// Gets all the defined attribute for type t.
        /// </summary>
        /// <typeparam name="TAttribute">The type of teh attribute to retrieve</typeparam>
        public static TAttribute[] Get<TAttribute>(Type t) where TAttribute : Attribute {
            if (t == null) {
                throw new ArgumentNullException("t");
            }
            return (TAttribute[])Attribute.GetCustomAttributes(t, typeof(TAttribute), true);
        }
        /// <summary>
        /// Gets all the defined attribute for type t.
        /// </summary>
        /// <typeparam name="TAttribute">The type of teh attribute to retrieve</typeparam>
        public static TAttribute[] Get<TAttribute>(Assembly asm) where TAttribute : Attribute
        {
            if (asm == null)
            {
                throw new ArgumentNullException("asm");
            }
            return (TAttribute[])Attribute.GetCustomAttributes(asm, typeof(TAttribute), true);
        }
    }

}